import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
#id
id = driver.find_element(By.CSS_SELECTOR,'#kw')
#class
class1 = driver.find_element(By.CSS_SELECTOR,'.s_ipt')
#标签和属性
input1 = driver.find_element(By.CSS_SELECTOR,'input[name="wd"]')
#层级
input2 = driver.find_element(By.CSS_SELECTOR,'form[id="form"] input[id="kw"]')
input3 = driver.find_element(By.CSS_SELECTOR,'form[id="form"]>span>input[id="kw"]')
#模糊
a1 = driver.find_element(By.CSS_SELECTOR,'a[href*="www"]')
#索引
form1 = driver.find_element(By.CSS_SELECTOR,'form[id="form"] :nth-child(2)')
form2 = driver.find_element(By.CSS_SELECTOR,'form[id="form"] :nth-of-type(2)')
#多条件查询
element = driver.find_element(By.CSS_SELECTOR,'input[autocomplete="off"][name="wd"]')
print(element.get_attribute("outerHTML"))